import React from "react";
class Content extends React.Component{
    constructor(props){
      super(props);
  
      this.state={
        data:[]
      }
    }
    // 挂载成功执行，且只执行一次
    componentDidMount(){
      fetch('https://cnodejs.org/api/v1/topics')
            .then(res=>res.json())
            .then(res=>{
              console.log(res)
              this.setState({data:res.data})
            })
    }
    
    render(){
      
      return <div>
        <ul>
          {
            this.state.data.map(item=><li key={item.id}>{item.title}</li>)
          }
        </ul>
      </div>
    }
}

export default Content;
